class ChatRoom:
    users = []
    password = ""
    visible = True
    def __init__(self, name, typ, visible, admin):
        self.name = name
        if typ in self._getroomtypes():
            self.typ = typ
        self.visible = visible
        self.admin = admin
        self.users.append(admin)

    def adduser(self,user):
        self.users.append(user)

    def getonline(self, mode = "class"):
        if mode == "class":
            return self.users
        if mode == "array":
            b = []
            for a in self.users:
                b.append(a.Name)
            return b

    def kick(self, user):
        self.users.remove(user)

    def search(self, user):
        if user in self.users:
            return user
        else:
            return 0
    
    def _getroomtypes(self):
        return ["Private", "Public"]

class ChatRooms:
    rooms = []
    def __init__(self):
        self._loadrooms()

    def _loadrooms(self):
        pass

    def _saverooms(self):
        pass

    def getall(self):
        b = []
        for a in self.rooms:
            b.append(a.name)
        return b

    def kick(self, room, user):
        i = self.rooms.index(room)
        if self.rooms[i].admin == user:
            self.rooms.delete(room)
            return 0
        if self.rooms[i].search(user) != 0:
            self.rooms[i].kick(user)
            return 0
        else:
            return 1
            
    def kickall(self, user):
        for a in self.rooms:
            if a.search(user) != 0:
                i = self.rooms.index(a)
                self.rooms[i].kick(user)
            if a.admin == user:
                self.rooms.delete(a)
                
    def delete(self, room):
        self.rooms.remove(room)
        
    def enter(self, room, user):
        i = self.rooms.index(room)
        if user in self.rooms[i].getonline():
            self.rooms[i].adduser(user)
            return 0
        else:
            return 1

    def create(self, room):
        self.rooms.append(room)

    def search(self, name):
        for a in self.rooms:
            if a.name == name:
                return a
        return 0
